package com.invest.tool.server.service.impl;

import com.invest.tool.server.bean.request.CompareBeanRequest;
import com.invest.tool.server.bean.response.CompareBeanResponse;
import com.invest.tool.server.service.AnalysisDataService;
import com.invest.tool.server.service.LiXingRenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service
public class AnalysisDataServiceImpl implements AnalysisDataService {

    @Autowired
    private LiXingRenService liXingRenService;

    @Override
    public Double averageMediumPE() {
        CompareBeanRequest request = new CompareBeanRequest();
        request.setStartDate("2001-08-18T00:45:08.616");
        request.setEndDate("2021-08-18T00:45:08.616");
        request.setStockCompareList(Arrays.asList(new CompareBeanRequest.StockCompare("false", "1000001000002.pm.pe_ttm.median")));
        request.setMacroCompareList(new ArrayList<>());
        request.setFundCompareList(new ArrayList<>());
        CompareBeanResponse response = liXingRenService.compareInfo(request);
//        List<Double> peList=new ArrayList<>();
        int count = 0;
        Double total = 0.0;
        List<Map> peList = (List) response.getMetricsData().get("1000001000002.pm.pe_ttm.median");
        for (Map map : peList) {
            count++;
            total = total + (Double) map.get("value");
        }
        return total/count;
    }
}
